﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace ERP.Classes
{
    public class cs_erp_nhommonanInfo
    {
        private int _id_nhom;
        private string _maql;
        private string _tennhom;

        public cs_erp_nhommonanInfo(int id_nhom, string maql, string tennhom)
        {
            this._id_nhom = id_nhom;
            this._maql = maql;
            this._tennhom = tennhom;

        }
        public cs_erp_nhommonanInfo()
        {
            this._id_nhom = 0;
            this._maql = " ";
            this._tennhom = " ";

        }
        public int id_nhom
        {
            get
            {
                return this._id_nhom;
            }
            set
            {
                this._id_nhom = value;
            }
        }
        public string maql
        {
            get
            {
                return this._maql;
            }
            set
            {
                this._maql = value;
            }
        }
        public string tennhom
        {
            get
            {
                return this._tennhom;
            }
            set
            {
                this._tennhom = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[4];
            paraName[0] = "@id_nhom";
            paraName[1] = "@maql";
            paraName[2] = "@tennhom";
            paraName[3] = "@option";
            object[] paraValue = new object[4];
            paraValue[0] = this._id_nhom;
            paraValue[1] = this._maql;
            paraValue[2] = this._tennhom;
            paraValue[3] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 4, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }
        
        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_ERP_NHOMMONAN", option);
        }

        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("ERP_NHOMMONAN", "");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._id_nhom = Convert.ToInt32(ds.Tables[0].Rows[0]["id_nhom"].ToString().Trim());
                this._maql = ds.Tables[0].Rows[0]["maql"].ToString().Trim();
                this._tennhom = ds.Tables[0].Rows[0]["tennhom"].ToString().Trim();
                return 1;
            }
            catch
            {
                return -1;
            }
        }

        public DataSet Get_List()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select id_nhom, maql, tennhom"
                + " from ERP_NHOMMONAN";
                ds = csdl.SelecSQL(sql);

                return ds;
            }
            catch
            {
                return null;
            }
        }

    }
}
